package daniel.suen.physics2d.shape;

import java.awt.geom.Ellipse2D;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;


public class Circle implements Shape{
	private PropertyChangeSupport support = new PropertyChangeSupport(this);

	Ellipse2D.Double data = new Ellipse2D.Double();
	
	public Circle(){
		
	}
	public Circle(double radius,double radiusX, double radiusY){
		setRadius(radius);
		setRadiusX(radiusX);
		setRadiusY(radiusY);
	}
	public Circle(Ellipse2D.Double data){
		this.data = data;
	}
	
//	/** 圆心x坐标*/
//	private double RadiusX;
//
//	/** 圆心y坐标 */
//	private double RadiusY;
//
//	/** 半径 */
//	private double radius;

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		support.addPropertyChangeListener(listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener listener) {
		support.removePropertyChangeListener(listener);
	}

	public double getRadiusX() {
		return data.getCenterX();
	}

	public void setRadiusX(double radiusX) {
		double oldVal = this.data.getCenterX();
		this.data.x = radiusX - this.data.getWidth()/2;
		support.firePropertyChange("radiusX",oldVal,this.data.x);
	}

	public double getRadiusY() {
		return this.data.getCenterY();
	}

	public void setRadiusY(double radiusY) {
		double oldVal = this.data.getCenterY();
		this.data.y = radiusY - this.data.getHeight()/2;
		support.firePropertyChange("radiusY",oldVal,this.data.y);
	}

	public double getRadius() {
		return this.data.getWidth()/2;
	}

	public void setRadius(double radius) {
		double oldVal = this.data.getWidth()/2;;
		this.data.width = radius*2;
		this.data.height = radius*2;
		support.firePropertyChange("radius",oldVal,radius);
	}

	public Ellipse2D.Double getData() {
		return data;
	}

	public void setData(Ellipse2D.Double data) {
		this.data = data;
	}
	
}